package com.example.module_d;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class Login extends AppCompatActivity implements View.OnClickListener {


    private EditText username;
    private EditText userpassword;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_login);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        TextView tv_login = findViewById(R.id.tv_login);
        tv_login.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        findViewById(R.id.longin).setOnClickListener(this);

        username = findViewById(R.id.username);
        userpassword = findViewById(R.id.userpassword);
    }

    @Override
    public void onClick(View view) {


        SharedPreferences spf = getSharedPreferences("config", MODE_PRIVATE);
        String name = spf.getString("name","");
        String email = spf.getString("email","");
        String phone = spf.getString("phone","");
        String password = spf.getString("password","");
        String repassword = spf.getString("repassword","");
        Log.d("Login","name ="+name);
        Log.d("Login",email);
        Log.d("Login",phone);
        Log.d("Login",password);
        Log.d("Login",repassword);

        String name1 =username.getText().toString();
        String password1 =userpassword.getText().toString();

        Log.d("Login",name1);
        Log.d("Login",password1);

        if (view.getId() == R.id.longin){
            if (password.equals(password1)&& name.equals(name1)){
                Toast.makeText(this, "登陆成功", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(Login.this,Admin.class);
                intent.putExtra("name",name1);
                startActivity(intent);
            }



        }
    }
}